package com.isias.system.Controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.isias.common.result.Result;
import com.isias.model.El.ElRepo;
import com.isias.model.system.SysUser;
import com.isias.model.vo.ElRepoQueryVo;
import com.isias.model.vo.SysUserQueryVo;
import com.isias.system.service.ElRepoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value="/admin/el/elrepo")
public class ElRepoController {
    @Autowired
    private ElRepoService elRepoService;


    /**
     * 分页查询
     */
    Page<ElRepo> pageparam = new Page<>();
    @GetMapping("{page}/{limit}")
    public Result SeletePage(@PathVariable Integer page, @PathVariable Integer limit, ElRepoQueryVo elRepoQueryVo){
        pageparam.setCurrent(page);
        pageparam.setSize(limit);
        IPage<ElRepo> iPage = elRepoService.SeletePage(pageparam,elRepoQueryVo);
        return Result.ok(iPage);


    }

    /**
     * 查询单个（用于数据回显）
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result GetById(@PathVariable String id){
        ElRepo elRepo = elRepoService.getById(id);
        if (elRepo != null){
            return Result.ok(elRepo);
        }
        return Result.fail(elRepo);
    }

    /**
     * 添加题库
     * @param elRepo
     * @return
     */
    @PostMapping
    public Result Add(@RequestBody ElRepo elRepo){

        if (elRepoService.save(elRepo)){
            return Result.ok();
        }
        return Result.fail();
    }

    /**
     * 修改单个
     * @param elRepo
     * @return
     */
    @PutMapping()
    public Result Update(@RequestBody ElRepo elRepo){
        if (elRepoService.updateById(elRepo)){
            return Result.ok();
        }
        return Result.fail();
    }

    /**
     * 删除单个
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result DeleteById(@PathVariable String id){
        if (elRepoService.removeById(id)){
            return Result.ok();
        }
        return Result.fail();
    }

    /**
     * 根据id列表删除
     */
    @DeleteMapping("/batchRemove")
    public Result batchRemove(@RequestBody List<Long> idList) {
        if (elRepoService.removeByIds(idList)) {
            return Result.ok();
        }else {
            return Result.fail();
        }
    }

}
